//this document is reloads
var page = page || {};
/*
 * option=[
 * 		{id:"",url:"",type:""},
 * ]
 * */
(function(page){
	function reloads (){
		var arr = page.reloads.defaults.arr;
		
		if(arr == null || arr.length==0){
			return;
		}
		reload(0);
	}
	function reload(index){
		var arr = page.reloads.defaults.arr;
		if(index>=arr.length){
			return;
		}
		if(arr[index].type.toLowerCase()=="img"){
			var img = document.getElementById(arr[index].id);
			img.src = arr[index].url;
			img.onload = function(){
				reload(++index);
			}
		}
		else if(arr[index].type.toLowerCase()=="script"){
			var script = document.createElement("script");
			script.src=arr[index].url;
			script.type = "text/javascript";
			script.onload = script.onreadystatechange = function(){
				if(! this.readyState     //这是FF的判断语句，因为ff下没有readyState这人值，IE的readyState肯定有值
			       ||this.readyState=='loaded'||this.readyState=='complete'// 这是IE的判断语句
			    ){
					reload(++index);
			    }
			};
			var head = document.getElementsByTagName("HEAD")[0];
			head.appendChild(script);
			head = null;
		}
	}
	
	function init(option){
		page.reloads.defaults.arr = option;
	}
	page.reloads = function(option){
		if(!option){
			return;
		}
		init(option);
		reloads();
	}
	page.reloads.defaults={
		arr:null,
		index:0
	}
})(page)